﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BeniBastanYaratProject.Yonetim
{
    public partial class SaglayiciDuzenle : System.Web.UI.Page
    {
        DBBaglantiDataContext db = new DBBaglantiDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack) return;
            if (Request.QueryString["saglayiciid"] != null)
            {
                int sdi = int.Parse(Request.QueryString["saglayiciid"]);
                var sorgu = (from x in db.Saglayicilars where x.SaglayiciID == sdi select x).SingleOrDefault();

                txtSFirmaAdi.Text = sorgu.SaglayiciFirmaAdi;
                txtSFirmaAdres.Text = sorgu.SaglayiciFirmaAdresi;
                txtSFirmaYetkli.Text = sorgu.SaglayiciFirmaYetkili;
                txtSFirmaTel.Text = sorgu.SaglayiciFirmaTelefon01;
                txtSFirmaTel2.Text = sorgu.SaglayiciFirmaTelefon02;
                txtSFirmaTel3.Text = sorgu.SaglayiciFirmaTelefon03;
                txtSFirmaFax.Text = sorgu.SaglayiciFirmaFax;
                txtSFirmaEposta.Text = sorgu.SaglayiciFirmaEposta;
                txtSFirmaNot.Text = sorgu.SaglayiciFirmaNot;
                ViewState["saglayiciid"] = sdi.ToString();
            }
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            int sdi = int.Parse(ViewState["saglayiciid"].ToString());
            var sorgu = (from x in db.Saglayicilars where x.SaglayiciID == sdi select x).SingleOrDefault();

            sorgu.SaglayiciFirmaAdi = txtSFirmaAdi.Text;
            sorgu.SaglayiciFirmaAdresi = txtSFirmaAdres.Text;
            sorgu.SaglayiciFirmaYetkili = txtSFirmaYetkli.Text;
            sorgu.SaglayiciFirmaTelefon01 = txtSFirmaTel.Text;
            sorgu.SaglayiciFirmaTelefon02 = txtSFirmaTel2.Text;
            sorgu.SaglayiciFirmaTelefon03 = txtSFirmaTel3.Text;
            sorgu.SaglayiciFirmaFax = txtSFirmaFax.Text;
            sorgu.SaglayiciFirmaEposta = txtSFirmaEposta.Text;
            sorgu.SaglayiciFirmaNot = txtSFirmaNot.Text;

            db.SubmitChanges();
            Response.Redirect("SaglayiciIslemleri.aspx");
        }
    }
}